package org.yty.travelagencyredis.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.yty.travelagencyredis.model.Entity.ChatGroupMember;
import org.yty.travelagencyredis.model.Entity.Result;
import org.yty.travelagencyredis.service.ChatGroupMemberService;

@RestController
@RequestMapping("/chat-group-member")
@RequiredArgsConstructor
public class ChatGroupMemberController {
    private final ChatGroupMemberService chatGroupMemberService;

    @PostMapping
    public Result<Void> save(@RequestBody ChatGroupMember chatGroupMember) {
        boolean success = chatGroupMemberService.save(chatGroupMember);
        if (!success){
            return Result.error("保存失败");
        }
        return Result.ok();
    }

    @DeleteMapping("/{chatGroupId}/{chatUserId}")
    public Result<Void> deleteByChatGroupIdAndChatUserId(@PathVariable String chatGroupId, @PathVariable String chatUserId) {
        chatGroupMemberService.deleteByChatGroupIdAndChatUserId(chatGroupId, chatUserId);
        return Result.ok();
    }
}
